package com.sh.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

@Configuration
public class RedisConfig {
    @Bean("myObjectRedisTemplate")
    public RedisTemplate<String, Object> myObjectRedisTemplate(RedisConnectionFactory connectionFactory){
        RedisTemplate<String, Object> objectObjectRedisTemplate = new RedisTemplate<>();
            objectObjectRedisTemplate.setConnectionFactory(connectionFactory);
            objectObjectRedisTemplate.afterPropertiesSet();

        objectObjectRedisTemplate.setKeySerializer(RedisSerializer.string());
        objectObjectRedisTemplate.setValueSerializer(RedisSerializer.java());
        objectObjectRedisTemplate.setHashKeySerializer(RedisSerializer.string());
        objectObjectRedisTemplate.setHashValueSerializer(RedisSerializer.java());
        return objectObjectRedisTemplate;
    }
    @Bean("myjosnRedisTemplate")
    public RedisTemplate<String, Object> myJsonRedisTemplate(RedisConnectionFactory connectionFactory){
        RedisTemplate<String, Object> objectObjectRedisTemplate = new RedisTemplate<>();
        objectObjectRedisTemplate.setConnectionFactory(connectionFactory);
        objectObjectRedisTemplate.afterPropertiesSet();

        objectObjectRedisTemplate.setKeySerializer(RedisSerializer.string());
        objectObjectRedisTemplate.setValueSerializer(RedisSerializer.json());
        objectObjectRedisTemplate.setHashKeySerializer(RedisSerializer.string());
        objectObjectRedisTemplate.setHashValueSerializer(RedisSerializer.json());
        return objectObjectRedisTemplate;
    }
}
